package com.tusuo.stds.util.validator;

import android.text.TextUtils;
import android.widget.EditText;

import com.andreabaccega.formedittextvalidator.Validator;

/**
 * @author J.Huang
 * @version 1.1
 *
 */

public class NameValidator extends Validator {

    public NameValidator(String _customErrorMessage) {
        super(_customErrorMessage);
    }

    @Override
    public boolean isValid(EditText et) {
        String name = et.getText().toString();
        // 最长不得超过8个汉字，或16个字节(数字，字母和下划线)
        String nameRegex = "^[\\u4e00-\\u9fa5\\dA-Za-z_]{1,16}$";
        return !TextUtils.isEmpty(name)
                && name.matches(nameRegex)
                && name.replaceAll("[^\\x00-\\xff]", "**").length() <= 16;
    }
}
